<template>
  <div id='updateUI'>
    <div class="newVersion">发现新版本,开始自动升级......</div>
    <div class="desc">{{desc}}</div>
  </div>
</template>
<script>
let electron = require("electron");
import { BrowserWindow, ipcRenderer } from "electron";
  export default {
    name: "updateUI",
    data() {
      return {
        desc:"",
      };
    },

    mounted() {
      self = this;
      ipcRenderer.on('message',(event,{message,data}) => {
        switch(message)
        {
          case "downloadProgress":
              var percent = data.percent || 0;
              percent = percent.toFixed(2);
              self.desc = "下载进度: "+ percent + "%";
          break;
          case "downloaded":
           self.desc = "下载进度:100% ";
            setTimeout(() => {
              ipcRenderer.send('updateNow');
            }, 1000);
            
          break;
        }
      });
    }
  };
</script>
<style scoped>
  * {
    margin: 0;
    padding: 0;
  }

  #updateUI {
    display: flex;
    position: fixed;
    bottom: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    padding: 20px;
    justify-content: center;
    align-content: center;
    align-items: center;
    background-color: rgb(155, 158, 161);
    box-sizing: border-box;
    border: 2px solid orange;
    flex-direction: column;
  }

  .newVersion {
    font-size: 2em;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
  }

  .desc {
    font-size: 30px;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 100;
    color: blue;
    padding: 30px;
  }
</style>